﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Newtonsoft.Json;
using System.Text;


namespace RepeaterTest
{
    /// <summary>
    /// DataTest 的摘要说明
    /// </summary>
    public class DataTest : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
           
            context.Response.ContentType = "application/json";
            int pindex = int.Parse(context.Request["pindex"]);
            int psize=int.Parse(context.Request["psize"]);
            List<object> list = new List<object>();
            
            list.Add(new { Row = 1, name = 2, pwd = 1234,__index=1 });
            list.Add(new { Row = 2, name = 3, pwd = 1234, __index = 2 });
            list.Add(new { Row = 3, name = 4, pwd = 1234, __index = 3 });
            list.Add(new { Row = 4, name = 5, pwd = 1234, __index = 4 });
            list.Add(new { Row = 5, name = 6, pwd = 1234, __index = 5 });
            list.Add(new { Row = 6, name = 7, pwd = 7234, __index = 6 });
            list.Add(new { Row = 7, name = 8, pwd = 1234, __index = 7 });
            list.Add(new { Row = 8, name = 9, pwd = 1234, __index = 8 });
            list.Add(new { Row = 9, name = 10, pwd = 1234, __index = 9 });
            list.Add(new { Row = 10, name = 11, pwd = 1234, __index = 10 });
            list.Add(new { Row = 11, name = 12, pwd = 1234, __index = 11 });
            list.Add(new { Row = 12, name = 13, pwd = 1234, __index = 12 });
            list.Add(new { Row = 13, name = 14, pwd = 1234, __index = 13 });
            list.Add(new { Row = 14, name = 15, pwd = 1234, __index = 14 });
            list.Add(new { Row = 15, name = 16, pwd = 1234, __index = 15 });
            list.Add(new { Row = 16, name = 17, pwd = 1234, __index = 16 });
            list.Add(new { Row = 16, name = 17, pwd = 1234, __index = 17 });
            list.Add(new { Row = 17, name = 18, pwd = 1234, __index = 18 });
            list.Add(new { Row = 18, name = 19, pwd = 1234, __index = 19 });
            list.Add(new { Row = 19, name = 20, pwd = 1234, __index = 20});
            list.Add(new { Row = 20, name = 21, pwd = 1234, __index = 21 });

            int pcount=0;
            if(list.Count%psize==0)
            {
            pcount=list.Count/psize;
            }else
            {
            pcount=list.Count/psize+1;
            }
            List<object> listData = new List<object>();

            for (int i = (pindex - 1) * psize; i <( pindex * psize > list.Count ? list.Count : pindex * psize); i++)
            {
               listData.Add(list[i]);
            }

                context.Response.Write(JsonConvert.SerializeObject(new { GridData = new { pager = new { pageSize = psize, pageIndex = pindex, itemCount =pcount  }, rows = listData } }));
//            context.Response.Write(JsonConvert.SerializeObject(new { pageIndex = 1, pageCount = 10, itemCount = false, pageSize = 20, pagers = 5, list }));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}